home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Demos / ByCompany / TipTop_Software / TipTop / Supplement / src / Ascii / AsciiSend3.m < prev    next >
Text File  |  1994-05-08  |  1KB  |  60 lines

  1. /* This script demonstrates a simple transfer protocol which uses a transfer
  2.    progress panel.  This is just like cat.
  3.  
  4. -> Neither file list nor file sizes are know.  We only know file names (as
  5.    we go along).  Example: XMODEM receive (only one file is received).
  6. */
  7. #import "TransferProgressProtocol.h"
  8. #import <libc.h>
  9. #define NOTIFYCHUNK 1024
  10.  
  11. static id remote;
  12.  
  13. /* When user clicks Abort button in the transfer progress panel,
  14.    SIGTERM is sent to the TickleTop process group. */
  15. void transfer_abort(int sig)
  16. {
  17.   [remote transferMessage:"Aborted!"];
  18.   sleep(1);
  19.   [remote transferEnd];
  20.   exit(0);
  21. }
  22.  
  23. int main(int argc, char **argv)
  24. {
  25.   struct stat statbuf;
  26.   int i,j,c;
  27.   FILE *fp;
  28.  
  29.   if(argc<=1) {
  30.     fprintf(stderr,"Usage: %s file ...\n",argv[0]);
  31.     exit(1);
  32.   }
  33. #ifdef __STRICT_BSD__
  34.   signal(SIGTERM,(int*)(int)transfer_abort);
  35. #else
  36.   signal(SIGTERM,(void*)(int)transfer_abort);
  37. #endif
  38.  
  39.   remote=getProgressListener();
  40.   [remote transferBegin:"Ascii Send"];
  41.  
  42.   for(i=1;i<argc;i++) {
  43.     if(access(argv[i],R_OK)<0 || stat(argv[i],&statbuf)<0
  44.        || (fp=fopen(argv[i],"r"))==NULL) continue;
  45.  
  46.     [remote transferFileBegin:argv[i]];
  47.     for(j=0;;j++) {
  48.       c=fgetc(fp);
  49.       if(c==EOF) break;
  50.       fputc(c,stdout);
  51.  
  52.       if(j%NOTIFYCHUNK==0) [remote transferProgress:j];
  53.     }
  54.     fclose(fp);
  55.   }
  56.  
  57.   [remote transferEnd];
  58.   exit(0);
  59. }
  60.